import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { rules} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
//列表数据
export const columns: BasicColumn[] = [
   {
    title: '姓名',
    align:"center",
    dataIndex: 'name'
   },
   {
    title: '性别',
    align:"center",
    dataIndex: 'sex_dictText'
   },
   {
    title: '电话',
    align:"center",
    dataIndex: 'phone'
   },
   {
    title: '创建会员日期',
    align:"center",
    dataIndex: 'memberDate',
    customRender:({text}) =>{
      return !text?"":(text.length>10?text.substr(0,10):text)
    },
   },
   {
    title: '套餐名称',
    align:"center",
    dataIndex: 'packageName_dictText'
   },
   {
    title: '会员有效期',
    align:"center",
    dataIndex: 'membershipPeriod',
    customRender:({text}) =>{
      return !text?"":(text.length>10?text.substr(0,10):text)
    },
   },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
	{
      label: "姓名",
      field: "name",
      component: 'Input',
      //colProps: {span: 6},
 	},
	{
      label: "性别",
      field: "sex",
      component: 'JDictSelectTag',
      componentProps:{
          dictCode:"sex"
      },
      //colProps: {span: 6},
 	},
	{
      label: "电话",
      field: "phone",
      component: 'Input',
      //colProps: {span: 6},
 	},
];

//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '姓名',
    field: 'name',
    component: 'Input',
  },
  {
    label: '性别',
    field: 'sex',
    component: 'JDictSelectTag',
    componentProps:{
        dictCode:"sex"
     },
  },
  {
    label: '电话',
    field: 'phone',
    component: 'Input',
  },
  {
    label: '创建会员日期',
    field: 'memberDate',
    component: 'DatePicker',
  },
  {
    label: '套餐名称',
    field: 'packageName',
    component: 'JDictSelectTag',
    componentProps:{
        dictCode:"membership_packages,package_name,package_name"
     },
  },
  {
    label: '会员有效期',
    field: 'membershipPeriod',
    component: 'DatePicker',
  },
	// TODO 主键隐藏字段，目前写死为ID
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];

//子表列表数据
export const memberExtendColumns: BasicColumn[] = [
   {
    title: '推荐人名称',
    align:"center",
    dataIndex: 'extendName'
   },
   {
    title: '联系电话',
    align:"center",
    dataIndex: 'phone'
   },
   {
    title: '是否优惠',
    align:"center",
    dataIndex: 'isFree',
    customRender:({text}) => {
       return  render.renderSwitch(text, [{text:'是',value:'Y'},{text:'否',value:'N'}])
     },
   },
];
//子表表单数据
export const memberExtendFormSchema: FormSchema[] = [
  // TODO 子表隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false
  },
  {
    label: '推荐人名称',
    field: 'extendName',
    component: 'JPopup',
    componentProps: ({ formActionType }) => {
        const {setFieldsValue} = formActionType;
        return{
            setFieldsValue:setFieldsValue,
            code:"seemember",
            fieldConfig: [
                { source: 'name', target: 'extendName' },
                { source: 'phone', target: 'phone' },
            ],
            multi:true
        }
    },

  },
  {
    label: '联系电话',
    field: 'phone',
    component: 'Input',
  },
  {
    label: '是否优惠',
    field: 'isFree',
     component: 'JSwitch',
     componentProps:{
     },
  },
];

// 高级查询数据
export const superQuerySchema = {
  name: {title: '姓名',order: 0,view: 'text', type: 'string',},
  sex: {title: '性别',order: 1,view: 'list', type: 'string',dictCode: 'sex',},
  phone: {title: '电话',order: 2,view: 'text', type: 'string',},
  memberDate: {title: '创建会员日期',order: 3,view: 'date', type: 'string',},
  packageName: {title: '套餐名称',order: 4,view: 'list', type: 'string',dictTable: "membership_packages", dictCode: 'package_name', dictText: 'package_name',},
  membershipPeriod: {title: '会员有效期',order: 5,view: 'date', type: 'string',},
};
